<?php

namespace frontend\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\Response;
use yii\base\ErrorException;
use yii\helpers\Html;
use common\models\member\Member;
use frontend\models\Fenhuis;
use frontend\models\Fenhui;
use yii\captcha\Captcha;
use common\models\Setting\Setting;
use common\models\notice\Notice;
use common\models\fenhuigrade\Fenhuigrade;
use common\models\notice\NoticeSearch;
use yii\web\UploadedFile;
use zhongkefu\zhongkefu;
use zhongkefu\helpers\Utils;
use frontend\models\FenhuiForm;
use yii\data\Pagination;

class MemberController extends Controller
{
    public $layout = 'user';
    public function actions()
    {
        $setting = Setting::findBySql('SELECT value FROM setting where id in(52,53,54)')->asArray()->all();
        $captchaConfig = array(
            'class' => 'zhongkefu\helpers\WanhuCaptcha',
            'height' => $setting[2]['value'],
            'width' => $setting[1]['value'],
            'maxLength' => 4,
            'minLength' => 4,
            'flag' => $setting[0]['value'],
        );

        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => $captchaConfig,

        ];
    }


    //会员基础信息显示
    public function actionInfo(){
        $fenhuis = $this->getfg();
        $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);

        return $this->render('info',[
            'member'=>$member,
            'fenhuis'=>$fenhuis,


        ]);
    }
    //更新会员基础信息
    public function actionUpdateinfo(){
        $ucenter = Member::findOne(Yii::$app->user->identity->getId());
        if(Yii::$app->request->post()){
            if(!empty(Yii::$app->request->post()['repassword']))
            {
                if(Yii::$app->security->validatePassword(Yii::$app->request->post()['oldpassword'], $ucenter->password_hash))
                {
                    $password = Yii::$app->request->post()['repassword'];
                    $ucenter->setPassword($password);
                    $ucenter->generateAuthKey();
                    $ucenter->save(false);
                    if($ucenter->save(false)){
                        \Yii::$app->getSession()->setFlash("success", '修改成功');
                        return $this->redirect(['/auth/logout']);
                    }
                    else
                    {
                         Yii::$app->session->setFlash('success', Yii::t('app', '修改失败！！'));
                    }
                }
                else{
                    Yii::$app->session->setFlash('success', Yii::t('app', '原密码输入错误！！'));
                    return $this->render('info', [
                        'model' => $ucenter,
                        'member'=>$ucenter,
                    ]);
                }
            }
            else
            {
                $ucenter->company = Yii::$app->request->post()['company'];
                if(!empty(Yii::$app->request->post()['loc_province'])){
                    $ucenter->loc_province = Yii::$app->request->post()['loc_province'];
                }
                if(!empty(Yii::$app->request->post()['loc_city'])){
                    $ucenter->loc_city = Yii::$app->request->post()['loc_city'];
                }
                if(!empty(Yii::$app->request->post()['loc_town'])){
                    $ucenter->loc_town = Yii::$app->request->post()['loc_town'];
                }
                $ucenter->address = Yii::$app->request->post()['address'];
                $ucenter->farentel = Yii::$app->request->post()['farentel'];
                $ucenter->grnum = Yii::$app->request->post()['grnum'];
                $ucenter->zhucezj = Yii::$app->request->post()['zhucezj'];
                $ucenter->faren = Yii::$app->request->post()['faren'];
                $ucenter->farenphone = Yii::$app->request->post()['farenphone'];
                $ucenter->farenemail = Yii::$app->request->post()['farenemail'];
                $ucenter->yyzhizao = Yii::$app->request->post()['yyzhizao'];
                $ucenter->zcdizhi = Yii::$app->request->post()['zcdizhi'];
                $ucenter->qychengli = Yii::$app->request->post()['qychengli'];
                $ucenter->qychenglizhi = Yii::$app->request->post()['qychenglizhi'];
                $ucenter->jyfanwei = Yii::$app->request->post()['jyfanwei'];
                $ucenter->card = Yii::$app->request->post()['card'];
                $siteRoot = Yii::$app->params['memberimg'];
                if(!empty($_FILES['yyzhizhaoimg']['name'])){
                    
                    $json1 = Utils::uploadfile($_FILES['yyzhizhaoimg']['tmp_name'],$_FILES['yyzhizhaoimg']['name'],$siteRoot);
                    $ucenter->yyzhizhaoimg = $json1;
                }
                $ucenter->faren = Yii::$app->request->post()['faren'];
               if(!empty($_FILES['cardz']['name'])){
                    
                    $json1 = Utils::uploadfile($_FILES['cardz']['tmp_name'],$_FILES['cardz']['name'],$siteRoot);
                    $ucenter->cardz = $json1;
                }
                if(!empty($_FILES['cardf']['name'])){
                    $json2 = Utils::uploadfile($_FILES['cardf']['tmp_name'],$_FILES['cardf']['name'],$siteRoot);
                    $ucenter->cardf = $json2;
                }
                if(!empty($_FILES['fwdengjiimg']['name'])){
                    $json3 = Utils::uploadfile($_FILES['fwdengjiimg']['tmp_name'],$_FILES['fwdengjiimg']['name'],$siteRoot);
                    $ucenter->fwdengjiimg = $json3;
                }
                if($ucenter->save(false))
                {
                    \Yii::$app->getSession()->setFlash("success", '修改成功');
                    return $this->redirect(['member/info']);
                }
            } 

            }
            
    }
    //我的消息列表页
    public function actionMessage(){
        $notice = Notice::find();
        $pages = new Pagination(['totalCount'=>$notice->count(), 'pageSize'=>'12']);  //分页
        //动态读取内容
        $datas = $notice->offset($pages->offset)
        ->limit($pages->limit)
        ->orderby('updated_at DESC')
        ->all();
        return $this->render('message',['list' => $datas,'pages' => $pages,'count'=>$notice->count()]);
    }
    //我的消息内页
    public function actionMessagepage($id){
        $message = Notice::find()->where(['id' => $id])->asArray()->one();
        $articles = Notice::find()->asArray()->all();
        foreach($articles as $k=>$t){
            if($t['id'] == $id){
                //$lastone = $t[$k-1]['id'];
                $last = $k - 1;
                $next = $k + 1;
                //$nextone = $t[($k+1)]['id'];
          }
      }

        if(isset($articles[$last])) {
            $lastone['id'] = $articles[$last]['id'];
            $lastone['name'] = $articles[$last]['title'];
        } else {
            $lastone['id'] = $id;
            $lastone['name'] = '没有了';
        }

        if(isset($articles[$next])) {
            $nextone['id'] = $articles[$next]['id'];
            $nextone['name'] = $articles[$next]['title'];
        } else {
            $nextone['id'] = $id;
            $nextone['name'] = '没有了';
        }
         return $this->render('messagepage',[
            'message'=>$message,
            'lastone' => $lastone,
            'nextone' => $nextone,
        ]);
        //$lastone =
        //$lastone = 
       
    }
    //开通会员
    public function actionOpenmember(){
        $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
        return $this->render('openmember',[
            'member'=>$member
        ]);
    }

    //显示密码页
    public function actionPwd(){
        return $this->render('pwd');
    }
	//修改密码
	public function actionUpdate()
    {
        $model = Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);

        if(Yii::$app->request->post()){
            if(Yii::$app->security->validatePassword(Yii::$app->request->post()['oldpassword'], $model->password_hash)){
				$password = Yii::$app->request->post()['repassword'];
				$model->setPassword($password);
				$model->generateAuthKey();
				if($model->save()){
					Yii::$app->session->setFlash('success', '密码修改成功！');
					return $this->redirect(['/auth/logout']);
                }else{
					Yii::$app->session->setFlash('success', "密码修改失败！");
					return $this->redirect(['/member/info']);
				}
            }else{
                Yii::$app->session->setFlash('success', Yii::t('app', '原密码输入错误！！'));
                return $this->render('pwd', [
                    'model' => $model,
                ]);
            }

        } else {
            return $this->render('pwd', [
                'model' => $model,
            ]);
        }
    }

    //通知消息
    public function actionNotice(){
        $notice = Notice::find()->all();
        return $this->render('notice',[
            'notice'=>$notice
        ]);
    }
    //通知消息详情
    public function actionNoticedetail(){
        $id = Yii::$app->request->get()['id'];
        $notice = Notice::find()->andWhere(['id'=>$id])->one();
        return $this->render('noticedetail',[
            'notice'=>$notice
        ]);
    }
    //营业执照
    public function actionLicence(){
        $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
         return $this->render('licence',[
            'member'=>$member
        ]);
    }
    //更新营业执照
    public function actionUpdatelicence(){
        $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
         $member->yyzhizao = Yii::$app->request->post()['yyzhizao'];
         $member->zzdengji = Yii::$app->request->post()['zzdengji'];
         $member->qychengli = Yii::$app->request->post()['qychengli'];
         $member->zjjigou = Yii::$app->request->post()['zjjigou'];
         $member->faren = Yii::$app->request->post()['faren'];
         $member->farentel = Yii::$app->request->post()['farentel'];
         $member->farensex = Yii::$app->request->post()['farensex'];
         $member->farenphone = Yii::$app->request->post()['farenphone'];
         $member->farenemail = Yii::$app->request->post()['farenemail'];
         $member->zhucezj = Yii::$app->request->post()['zhucezj'];
         $member->zcdizhi = Yii::$app->request->post()['zcdizhi'];
         $member->zcyoubian = Yii::$app->request->post()['zcyoubian'];
         $member->jyfanwei = Yii::$app->request->post()['jyfanwei'];
         $member->frdaibiaojj = Yii::$app->request->post()['frdaibiaojj'];

        $siteRoot = Yii::$app->params['memberimg'];
       if(!empty($_FILES['yyzhizhaoimg']['name'])){
            $json1 = Utils::uploadfile($_FILES['yyzhizhaoimg']['tmp_name'],$_FILES['yyzhizhaoimg']['name'],$siteRoot);
            $member->yyzhizhaoimg = $json1;
        }
        if(!empty($_FILES['fwdengjiimg']['name'])){
            $json2 = Utils::uploadfile($_FILES['fwdengjiimg']['tmp_name'],$_FILES['fwdengjiimg']['name'],$siteRoot);
            $member->fwdengjiimg = $json2;
        }
   
         if(!empty($_FILES['zzjigouimg']['name'])){
            $json3 = Utils::uploadfile($_FILES['zzjigouimg']['tmp_name'],$_FILES['zzjigouimg']['name'],$siteRoot);
            $member->zzjigouimg = $json3;
        }
        
         if($member->save(false)){
              return $this->redirect(['member/licence']);
         }
    }
    //企业资料
    public function actionBusdetail(){
         $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
         return $this->render('busdetail',[
            'member'=>$member
        ]);
    }
    //更新企业资料
    public function actionUpdatebusdetail(){
         $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
         $member->xingzhi = Yii::$app->request->post()['xingzhi'];
         $member->moshi = Yii::$app->request->post()['moshi'];
         $member->pinpai = Yii::$app->request->post()['pinpai'];
         $member->daipinpai = Yii::$app->request->post()['daipinpai'];
         $member->bennum = Yii::$app->request->post()['bennum'];
         $member->grnum = Yii::$app->request->post()['grnum'];
         $member->nianmoney = Yii::$app->request->post()['nianmoney'];
         $member->wairatio = Yii::$app->request->post()['wairatio'];
         $member->caigoutoubiao = Yii::$app->request->post()['caigoutoubiao'];
         if($member->save(false)){
              return $this->redirect(['member/busdetail']);
         }
    }
	//实名认证
	public function actionNameauth(){
		$member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
         return $this->render('nameauth',[
            'member'=>$member
        ]);
	}
	
	//更新实名认证
    public function actionUpdatenameauth(){
        $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
         $member->realname = Yii::$app->request->post()['realname'];
         $member->card = Yii::$app->request->post()['card'];

        $siteRoot = Yii::$app->params['memberimg'];
           if(!empty($_FILES['cardz']['name'])){
                
                $json1 = Utils::uploadfile($_FILES['cardz']['tmp_name'],$_FILES['cardz']['name'],$siteRoot);
                $member->cardz = $json1;
            }
            if(!empty($_FILES['cardf']['name'])){
                $json2 = Utils::uploadfile($_FILES['cardf']['tmp_name'],$_FILES['cardf']['name'],$siteRoot);
                $member->cardf = $json2;
            }

        
         if($member->save(false)){
			 alert("提交成功！");
             return $this->redirect(['member/nameauth']);
         }
    }
	//认证资料管理
	public function actionAuthmange(){
		$member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
		$cardz = json_decode($member->cardz, true);
		$cardf = json_decode($member->cardf, true);
         return $this->render('authmange',[
            'member'=>$member,
			'cardz'=>$cardz,
			'cardf'=>$cardf
        ]);		
	}
//    //申请入会
//    public function actionApply(){
//        $member = Member::findOne(Yii::$app->user->identity->getId());
//        if($member['status']!="30" && $member['status']!="0")
//        {
//            if($member['status'] == "10")
//            {
//                $member['status'] = "您的申请已提交成功，请等待后台管理员审核!";
//            }
//            if($member['status'] == "20")
//            {
//                $member['status'] = "您的申请已通过!";
//            }
//            return $this->render('applypage',['member'=>$member]);
//        }
//        else
//        {
//            return $this->render('apply',['member'=>$member]);
//        }
//
//    }
    public function actionApply_association(){
        //填写申请信息
        if($_POST){
            $ucenter = Member::findOne(Yii::$app->user->identity->getId());
            $ucenter->company = Yii::$app->request->post()['company'];
            if(!empty(Yii::$app->request->post()['loc_province'])){
                $ucenter->loc_province = Yii::$app->request->post()['loc_province'];
            }
            if(!empty(Yii::$app->request->post()['loc_city'])){
                $ucenter->loc_city = Yii::$app->request->post()['loc_city'];
            }
            if(!empty(Yii::$app->request->post()['loc_town'])){
                $ucenter->loc_town = Yii::$app->request->post()['loc_town'];
            }
                $ucenter->address = Yii::$app->request->post()['address'];
                $ucenter->farentel = Yii::$app->request->post()['farentel'];
                $ucenter->grnum = Yii::$app->request->post()['grnum'];
                $ucenter->zhucezj = Yii::$app->request->post()['zhucezj'];
                $ucenter->faren = Yii::$app->request->post()['faren'];
                $ucenter->farenphone = Yii::$app->request->post()['farenphone'];
                $ucenter->farenemail = Yii::$app->request->post()['farenemail'];
                $ucenter->yyzhizao = Yii::$app->request->post()['yyzhizao'];
                $ucenter->zcdizhi = Yii::$app->request->post()['zcdizhi'];
                $ucenter->qychengli = Yii::$app->request->post()['qychengli'];
                $ucenter->qychenglizhi = Yii::$app->request->post()['qychenglizhi'];
                $ucenter->jyfanwei = Yii::$app->request->post()['jyfanwei'];
                $ucenter->card = Yii::$app->request->post()['card'];
                $ucenter->status = Yii::$app->request->post()['status'];
                $siteRoot = Yii::$app->params['memberimg'];
                if(!empty($_FILES['yyzhizhaoimg']['name'])){
                    
                    $json1 = Utils::uploadfile($_FILES['yyzhizhaoimg']['tmp_name'],$_FILES['yyzhizhaoimg']['name'],$siteRoot);
                    $ucenter->yyzhizhaoimg = $json1;
                }
                $ucenter->faren = Yii::$app->request->post()['faren'];
               if(!empty($_FILES['cardz']['name'])){
                    
                    $json1 = Utils::uploadfile($_FILES['cardz']['tmp_name'],$_FILES['cardz']['name'],$siteRoot);
                    $ucenter->cardz = $json1;
                }
                if(!empty($_FILES['cardf']['name'])){
                    $json2 = Utils::uploadfile($_FILES['cardf']['tmp_name'],$_FILES['cardf']['name'],$siteRoot);
                    $ucenter->cardf = $json2;
                }
                if(!empty($_FILES['fwdengjiimg']['name'])){
                    $json3 = Utils::uploadfile($_FILES['fwdengjiimg']['tmp_name'],$_FILES['fwdengjiimg']['name'],$siteRoot);
                    $ucenter->fwdengjiimg = $json3;
                }
                if($ucenter->save(false))
                {
                    \Yii::$app->getSession()->setFlash("success", '修改成功');
                    return $this->redirect(['member/apply']);
                }
            return $this->redirect(['member/apply_association']);
        }
        //显示申请信息
        $member = Member::findOne(Yii::$app->user->identity->getId());
        $yyzhizhaoimg = json_decode($member->yyzhizhaoimg, true);
        $fwdengjiimg = json_decode($member->fwdengjiimg, true);
        $cardz = json_decode($member->cardz, true);
        $cardf = json_decode($member->cardf, true);
        return $this->render('apply_association',['member'=>$member,'yyzhizhaoimg' =>$yyzhizhaoimg,
            'fwdengjiimg' =>$fwdengjiimg,
            'cardz' =>$cardz,
            'cardf' =>$cardf]);
	}
    //打印申请表 zsn 20161117
    public function actionPrint_application(){
        $userinfo = Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
        $member = FenhuiForm::findOne(['userid'=>\Yii::$app->user->identity->getId()]);
        return $this->render('print_application',['member'=>$member,'userinfo'=>$userinfo]);
    }

    public static function getfg(){
        $arr = Fenhuigrade::find()->where(['status'=>10])->asArray()->all();
        return $arr;
    }


    //防水申请one zsn 20170107
    public function actionApplyone($id){
        $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
        $uid = $member['id'];
        //当前分会
        $grade = Fenhuigrade::find()->where(['status'=>10,'id'=>$id])->one();
        $fenhui =  Fenhuis::findOne(['userid'=>$uid,'grade'=>$id]);
        if($fenhui){

        }else{
            $fenhui = new Fenhuis();
        }
        $fenhuis = $this->getfg();
        $info = Fenhui::find()->where(['userid'=>$uid,'grade'=>$id])->asArray()->one();
        $shangbiaotu = json_decode($info['shangbiaotu'], true);

        //填写申请信息
        if(Yii::$app->request->post()){


//            print_r(Yii::$app->request->post());exit;
                $fenhui->userid = $member['id'];
                $fenhui->qiyemingcheng = Yii::$app->request->post()['qiyemingcheng'];
                $fenhui->farendaibiao = Yii::$app->request->post()['farendaibiao'];
                $fenhui->farentel = Yii::$app->request->post()['farentel'];
                $fenhui->grade = $id;
//            $fenhui->farenmobile = Yii::$app->request->post()['farenmobile'];
                $fenhui->farenfax = Yii::$app->request->post()['farenfax'];
                $fenhui->zhiwu = Yii::$app->request->post()['zhiwu'];
                $fenhui->qiyexingzhi = Yii::$app->request->post()['qiyexingzhi'];
                $fenhui->qiyewangzhi = Yii::$app->request->post()['qiyewangzhi'];
                $fenhui->province = Yii::$app->request->post()['province'];
                $fenhui->city = Yii::$app->request->post()['city'];
                $fenhui->towm = Yii::$app->request->post()['towm'];
                $fenhui->qiyedizhi = Yii::$app->request->post()['qiyedizhi'];
                $fenhui->youbian = Yii::$app->request->post()['youbian'];
                $fenhui->zhucezijin = Yii::$app->request->post()['zhucezijin'];
                $fenhui->email = Yii::$app->request->post()['email'];
                $fenhui->sbwenzi = Yii::$app->request->post()['sbwenzi'];
                $fenhui->qiyejianjie = Yii::$app->request->post()['qiyejianjie'];
                $fenhui->verifyCode = Yii::$app->request->post()['code'];
                $siteRoot = Yii::$app->params['memberimg'];

                if (!empty($_FILES['shangbiaotu']['name'])) {

                    $json1 = Utils::uploadfile($_FILES['shangbiaotu']['tmp_name'], $_FILES['shangbiaotu']['name'], $siteRoot);
                    $fenhui->shangbiaotu = $json1;
                }

                if ($fenhui->save()) {
                    return $this->redirect(['applytwo','id' => $id]);

                } else {
                    yii::$app->getSession()->setFlash('error', '验证码错误');
                }
            }
        return $this->render('applyone',[
            'id'=>$id,
            'member'=>$member,
            'info'=>$info,
            'shangbiaotu'=>$shangbiaotu,
            'grade'=>$grade,
            'fenhui'=>$fenhui,
            'fenhuis'=>$fenhuis,
        ]);
    }
    //防水申请two zsn 20170107
    public function actionApplytwo($id){
        $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
        $uid = $member['id'];
        $info = Fenhui::find()->where(['userid'=>$uid,'grade'=>$id])->asArray()->one();
        $grade = Fenhuigrade::find()->where(['status'=>10,'id'=>$id])->one();
        $fenhui =  Fenhui::findOne(['userid'=>$uid,'grade'=>$id]);
        $fenhuis = $this->getfg();
        $yyzhizhaoimg = json_decode($info['yyzhizhaoimg'], true);
        $shuiwudenji = json_decode($info['shuiwudenji'], true);
        $zhuzhijgdmz = json_decode($info['zhuzhijgdmz'], true);
        //填写申请信息
        if(Yii::$app->request->post()){

            $fenhui->yyzhizao = Yii::$app->request->post()['yyzhizao'];
            $fenhui->shuiwudj = Yii::$app->request->post()['shuiwudj'];
            $fenhui->chenglidate = Yii::$app->request->post()['chenglidate'];
            $fenhui->zuzhijgdm = Yii::$app->request->post()['zuzhijgdm'];
            $fenhui->danweixz = Yii::$app->request->post()['danweixz'];
            $fenhui->danweizjlx = Yii::$app->request->post()['danweizjlx'];
            $fenhui->zhubanzjhm = Yii::$app->request->post()['zhubanzjhm'];
            $fenhui->zhucedizhi = Yii::$app->request->post()['zhucedizhi'];
            $fenhui->zhubanzjhm = Yii::$app->request->post()['zhubanzjhm'];
            $fenhui->jyfanwei = Yii::$app->request->post()['jyfanwei'];
            $fenhui->status = Yii::$app->request->post()['status'];
            $fenhui->farenjianjie = Yii::$app->request->post()['farenjianjie'];
            $siteRoot = Yii::$app->params['memberimg'];
            if (!empty($_FILES['yyzhizhaoimg']['name'])) {

                $json1 = Utils::uploadfile($_FILES['yyzhizhaoimg']['tmp_name'], $_FILES['yyzhizhaoimg']['name'], $siteRoot);
                $fenhui->yyzhizhaoimg = $json1;
            }
            if (!empty($_FILES['shuiwudenji']['name'])) {

                $json2 = Utils::uploadfile($_FILES['shuiwudenji']['tmp_name'], $_FILES['shuiwudenji']['name'], $siteRoot);
                $fenhui->shuiwudenji = $json2;
            }
            if (!empty($_FILES['zhuzhijgdmz']['name'])) {

                $json3 = Utils::uploadfile($_FILES['zhuzhijgdmz']['tmp_name'], $_FILES['zhuzhijgdmz']['name'], $siteRoot);
                $fenhui->zhuzhijgdmz = $json3;
            }

            if ($fenhui->save()) {

                return $this->redirect(['applythree','id' => $id]);
            }else{

                yii::$app->getSession()->setFlash('error', '提交失败');
            }

        }
        return $this->render('applytwo',[
            'id'=>$id,
            'member'=>$member,
            'grade'=>$grade,
            'yyzhizhaoimg'=>$yyzhizhaoimg,
            'shuiwudenji'=>$shuiwudenji,
            'zhuzhijgdmz'=>$zhuzhijgdmz,
            'info'=>$info,
            'fenhui'=>$fenhui,
            'fenhuis'=>$fenhuis,
        ]);
    }
    //防水申请three zsn 20170107
    public function actionApplythree($id){
        $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
        $uid = $member['id'];
        $info = Fenhui::find()->where(['userid'=>$uid,'grade'=>$id])->asArray()->one();
        $grade = Fenhuigrade::find()->where(['status'=>10,'id'=>$id])->one();
        $fenhui =  Fenhui::findOne(['userid'=>$uid,'grade'=>$id]);
        $fenhuis = $this->getfg();
        //填写申请信息
        if(Yii::$app->request->post()){
            $fenhui->jymoshi = Yii::$app->request->post()['jymoshi'];
            $fenhui->qiyepinpai = Yii::$app->request->post()['qiyepinpai'];
            $fenhui->dailipinpai = Yii::$app->request->post()['dailipinpai'];
            $fenhui->bennum = Yii::$app->request->post()['bennum'];
            $fenhui->qiyerenshu = Yii::$app->request->post()['qiyerenshu'];
            $fenhui->waixiao = Yii::$app->request->post()['waixiao'];
            $fenhui->chanpinzl = Yii::$app->request->post()['chanpinzl'];
            $fenhui->toubiao = Yii::$app->request->post()['toubiao'];
            $fenhui->status = 3;
//            print_r(Yii::$app->request->post());exit;
            //表格存数据库
            if ($fenhui->save()) {

                echo '<script>alert("提交成功");window.location.href="/member/info"; </script>';

            }else{
                yii::$app->getSession()->setFlash('error', '提交失败');
            }

        }
        return $this->render('applythree',[
            'id'=>$id,
            'member'=>$member,
            'grade'=>$grade,
            'info'=>$info,
            'fenhui'=>$fenhui,
            'fenhuis'=>$fenhuis,
        ]);
    }
    //缴费
    public function actionJiaofei(){
        $member =  Member::findOne(['id'=>\Yii::$app->user->identity->getId()]);
        $fenhuis = $this->getfg();
        return $this->render('jiaofei',[
            'member'=>$member,
            'fenhuis'=>$fenhuis,

        ]);
    }
}